package com.interview.dao;

import com.interview.pojo.Article;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface ArticleMapper extends Mapper<Article> {






    //查询全部文章  按时间倒序
    @Select("select * from article  where 1=1 ORDER BY time DESC")
    @Results(id = "resu",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "catalogue_id",column = "catalogue_id"),
            @Result(property = "answer",column="answer"),
            @Result(property = "context",column="context"),
            @Result(property = "time",column="time"),
            @Result(property = "head",column="head"),

    })
    public List<Article> queryAll();

    //查询全部文章的数量
    @Select("select count(*) from article")
    public int query_Count();


    //查询随机10篇文章
    @Select("select * from article where 1=1 order by rand() limit 10;")
    List<Article> queryRandom(); //随机查询10篇

    //查询推荐文章  4篇
    @Select("select * from article  where 1=1 order by rand() limit 4")
    public List<Article>  queryRecommend();


    @Select("select count(*) FROM  article  where   catalogue_id=#{id}")
    public  int count(@Param("id") String id);

    //通过日期查询数量

    @Select("select count(*) from article where  time>=#{time1} and time<=#{time2}")
    public  int time_count(String time1,String time2);

}
